//懒汉模式
class singletonLazy{
    private  static volatile singletonLazy instance=null;
    //这里是保证了内存可见性
    private singletonLazy(){
    }
   public static singletonLazy getInstance(){
       if(instance==null){//判断是否要加锁
           synchronized (singletonLazy.class) {
               if(instance==null) {//这里判断是否要创建对象
                   instance = new singletonLazy();
               }
           }
       }
       return  instance;
   }
}
public class ThreadDemo2 {
    public static void main(String[] args) {
        singletonLazy s1=singletonLazy.getInstance();
        singletonLazy s2=singletonLazy.getInstance();
        System.out.println(s1==s2);
    }
}
